﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Views_Admin_LoaiTu : System.Web.UI.Page
{
    QLloaitu lt = new QLloaitu();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            GridView1.DataSource = lt.Load_loaitu();
            GridView1.DataBind();
            if (Session["MaTu"] != null)
            {
                string matu = (string)Session["MaTu"];
                int MaTu = int.Parse(matu);
                FormView1.DataSource = lt.Load_tenloaitu(MaTu);
            }
            else
                return;
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {

    }
    protected void btnthem_Click(object sender, EventArgs e)
    {
        lt.Them_loaitu(txtten.Text);
        GridView1.DataSource = lt.Load_loaitu();
        GridView1.DataBind();
        MultiView1.SetActiveView(View1);

    }
    protected void btnback_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
    }


    protected void btnthemmoi_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View3);
    }
    protected void btntrove_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string matu = GridView1.DataKeys[e.NewEditIndex].Value.ToString();
        Session["MaTu"] = matu;
        MultiView1.SetActiveView(View2);
        //View2.
    }
    protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
    {
        if (MultiView1.ActiveViewIndex==1)
        {
            string matu = (string)Session["MaTu"];
            int MaTu = int.Parse(matu);
            if (matu != null)
            {
                FormView1.DataSource = lt.Load_tenloaitu(MaTu);
                FormView1.DataBind();
            }

        }
    }
    protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
    {
        if (e.CommandName == "update")
        {
            string matu = (string)Session["MaTu"];
            int MaTu = int.Parse(matu);
            TextBox ten = (TextBox)FormView1.FindControl("txttenloai");
            lt.update_loaitu(MaTu,ten.Text);
            FormView1.ChangeMode(FormViewMode.ReadOnly);
            GridView1.DataSource = lt.Load_loaitu();
            GridView1.DataBind();
            MultiView1.SetActiveView(View1);
        }
    }

}